<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();



include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');

?>

<h3>Portals by Geographical Type</h3>


<?

$sql = array();
$sql['columns'] = '*';
$sql['tables'] = array();
$sql['tables'][] = "portal";
$sql['wheres'] = array();

$sql['wheres'][] = "status_id = 1";
$sql['wheres'][] = "public = 'Y'";
if (empty($_GET['all'])) 
	$sql['wheres'][] = "type NOT IN ('','Other')";

$sql['order'] = "(type=''),type+0,portal_id DESC";



$query = sqlMakeQuery($sql);

$data = getAssoc($query);



if ($data) {
	$last = -1;
	foreach ($data as $id => $c) {
		$count = count_active($id);
		
		if ($count) {
			if ($last != $c['type']) {
				if ($last != -1) {
					print "</ul>";
				}
				print "<p><b>".($c['type']?he($c['type']):'<i>unknown</i>')."</b></p>";
				print "<ul class=\"list\">";
				$last = $c['type'];
			}

			print "<li>";
			print "<b><a href=\"http://".hec('domain').".portal.geographs.org/\" target=\"_blank\">".hec('title')."</a></b>";
		
			print " [$count images]";
		
			if (!empty($_SESSION['user_id']) && $c['user_id'] == $_SESSION['user_id']) {
				print "&middot; <a href=\"portal.php?id=$id\" class=\"edit\">Overview</a>";
				print "&middot; <a href=\"filters.php?id=$id\" class=\"edit\">Filters</a> ";

			}
			print "</li>";
		}
	}
	print "</ul>";
	
	#print "<p><a href=\"edit.php\">Create your own</a>!</p>";
	print "</div>";
} else {
	print "<p>No Portals to show at this time. <a href=\"edit.php\">Create one</a>!</p>";
}


include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');
